package com.neuedu.javase;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-23 9:01
 * 描述 : 数组的操作
 */
public class MyArray {
    public static void main(String[] args) {

        com.mysql.jdbc.Driver d;

       /* String name ="金山";
        int age  = 18;
        double sal = 999999.99;*/

        /**
         *  基础类型
         *      字符   char
         *      boolean  boolean
         *      整形     byte short int long
         *      浮点型    float  double
         *  引用类型
         *      数组
         *      对象
         *
         */


       //数组是引用类型
//        数组的声明
//          int ages[] = new int[len];

        //声明一个 年龄的数组，数据类型是 int
        //Java中的数据是不可变长的，
//        int ages[] = new int[35];
//        double[] sals = new double[35];
//        String names[] =  new String[35];

        /**
         * 使用固定的值进行初始化
         */
        int ages[] = { 20,20,21,19  };
        String names[] = {"张三","李四","王五","赵六"};



//        通过length属性获取数组的长度

        System.out.println("ages.length = " + ages.length);
        System.out.println("names.length = " + names.length);



        //访问元素
        //通过   数组名[下标] 访问数组个每个内容  下标从0 开始 到 length-1
        System.out.println("ages[0] = " + ages[0]);
        System.out.println("ages[1] = " + ages[1]);
        System.out.println("ages[2] = " + ages[2]);
        System.out.println("ages[3] = " + ages[3]);


        System.out.println();
        System.out.println("names[0] = " + names[0]);
        System.out.println("names[1] = " + names[1]);
        System.out.println("names[2] = " + names[2]);
        System.out.println("names[3] = " + names[3]);

        //设置数组的某一个元素
        names[0] = names[0] + "修改";
        System.out.println();
        System.out.println("names[0] = " + names[0]);
        System.out.println("names[1] = " + names[1]);
        System.out.println("names[2] = " + names[2]);
        System.out.println("names[3] = " + names[3]);


        System.out.println("=================================================");
        System.out.println("=================================================");
        System.out.println("===============遍历数组===========================");
        System.out.println("=================================================");

        //数组的遍历
        for (int i = 0; i <  names.length ; i++) {
            System.out.println("names["+i+"] = " + names[i]);
        }


        //names.length.fori
//        for (int i = 0; i < names.length; i++) {
//
//        }


        System.out.println("================================================");
        System.out.println("=================增强的for  1.6======================");
        System.out.println("================================================");

        for (String name : names) {
            System.out.println("name = " + name);
        }


        System.out.println("\r\n");
        //数组创建完成之后 有默认值
        double[] sals = new double[10];
        for (double sal : sals) {
            System.out.println(sal);
        }

        for (int i = 0; i < sals.length; i++) {
            System.out.println("sals[i] = " + sals[i]);
        }


        System.out.println("int 的默认值");
        int  myarr[] = new int[10];
        for (int i = 0; i < myarr.length; i++) {
            System.out.println("myarr[i] = " + myarr[i]);
        }

        /**
         *  char     空字符
         *  整形        0
         *  boolean    false
         *  浮点型  float 0.0 double  0.0
         */

        char chrs[] = new char[10];
        System.out.println("chrs 的默认值");
        for (int i = 0; i < chrs.length; i++) {
            System.out.println("chrs[i] =" + chrs[i]+"end");
        }


        boolean pass[] = new boolean[10];
        System.out.println("boolean 的默认值");
        for (int i = 0; i < pass.length; i++) {
            System.out.println("pass[i] =" + pass[i]);
        }


        String strs[] = new String[10];
        System.out.println("String 的默认值");
        for (int i = 0; i < strs.length; i++) {
            System.out.println("strs[i] =" + strs[i]);
        }





    }
}
